<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no">

    <title>INSPINIA | Dashboard</title>
    <link rel="stylesheet" href="../../plugins/layui/css/layui.css"/>
    <link rel="stylesheet" href="../../css/fa.css"/>
    <link rel="stylesheet" href="../../css/icon.css"/>
    <link rel="stylesheet" href="../../css/ares_animate.min.css"/>
    <link rel="stylesheet" href="../../css/ares_hover_variant.min.css"/>
    <link rel="stylesheet" href="../../css/ares_reboot.css"/>
    <link rel="stylesheet" href="../../css/app.min.css"/>
    <link rel="stylesheet" href="../../css/iframe.css"/>

    <link href="../../legacy/plugins/bootstrap3.3.4/bootstrap.min.css" rel="stylesheet">
    <link href="../../legacy/css/bootstrap-overwrite.css" rel="stylesheet">
    <link href="../../legacy/plugins/jqpagination/jqpagination.css" rel="stylesheet">
    <link href="../../legacy/plugins/jqGrid/ui.jqgrid.css" rel="stylesheet">
    <link href="../../legacy/plugins/toastr/toastr.min.css" rel="stylesheet">
    <link href="../../legacy/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="../../legacy/css/style.css" rel="stylesheet">
    <link href="../../legacy/css/mandy-style.css" rel="stylesheet">
    <!-- <link href="/css/bootstrap.min.css" rel="stylesheet">
     <link href="/css/bootstrap-overwrite.css" rel="stylesheet">
     <link href="/css/plugins/jQueryUI/jquery-ui-1.10.4.custom.min.css" rel="stylesheet">
     <link href="/css/plugins/jqGrid/ui.jqgrid.css" rel="stylesheet">
     <link href="/css/jqpagination.css" rel="stylesheet">

     <link href="/css/font-awesome/css/font-awesome.css" rel="stylesheet">

     &lt;!&ndash; Toastr style &ndash;&gt;
     <link href="/css/plugins/toastr/toastr.min.css" rel="stylesheet">

     &lt;!&ndash; Gritter &ndash;&gt;
     <link href="/js/plugins/gritter/jquery.gritter.css" rel="stylesheet">

     <link href="/css/animate.css" rel="stylesheet">
     <link href="/css/style.css" rel="stylesheet">
     <link href="/css/ics/common.css" rel="stylesheet">-->

    <style>
        .btn-w-80 {
            width: 80px;
            font-size: 13px !important;
        }

        th {
            text-align: center !important;
        }

        th:nth-child(5n+1) {
            width: 12% !important;
        }

        th:nth-child(5n+2) {
            width: 26% !important;
        }

        th:nth-child(5n+3) {
            width: 16% !important;
        }

        th:nth-child(5n+4) {
            width: 31% !important;
        }

        th:nth-child(5n+5) {
            width: 15% !important;
        }

        th[role='columnheader']:nth-child(6n+2) {
            width: 12% !important;
        }

        th[role='columnheader']:nth-child(6n+3) {
            width: 26% !important;
        }

        th[role='columnheader']:nth-child(6n+4) {
            width: 16% !important;
        }

        th[role='columnheader']:nth-child(6n+5) {
            width: 31% !important;
        }

        th[role='columnheader']:nth-child(6n+6) {
            width: 15% !important;
        }

        td[role='gridcell']:nth-child(6n+2) {
            width: 12% !important;
        }

        td[role='gridcell']:nth-child(6n+3) {
            width: 26% !important;
        }

        td[role='gridcell']:nth-child(6n+4) {
            width: 16% !important;
        }

        td[role='gridcell']:nth-child(6n+5) {
            width: 31% !important;
        }

        td[role='gridcell']:nth-child(6n+6) {
            width: 15% !important;
        }

        .ui-jqgrid-view {
            font-size: 13px !important;
        }

        .inline-block {
            display: inline-block;
        }

        #transfer-in, #transfer-out, #clinic, #training-plan, #treatment-record, #report td {
            text-align: center !important;
        }

        .info .row .ibox h3 {
            display: inline-block;
        }

        .time-axis {
            margin: 40px 0;
        }

        .time-axis-block {
            float: left;
            width: 25%;
            margin-bottom: 20px;
            /* cursor: pointer; */
        }

        .time-axis-icon {
            text-align: center;
            color: #ccc;
            position: relative;
            border-top: 1px solid #ddd;
            height: 15px;
        }

        .time-axis-block.active .time-axis-icon {
            color: #3399FF;
        }

        .time-axis-icon i {
            position: absolute;
            top: -9px;
        }

        .time-axis-div {
            width: 99%;
            text-align: center;
            border: 3px solid #ccc;
            border-radius: 10px;
            margin: 0 auto;
            padding: 5px;
        }

        .time-axis-div p {
            margin-bottom: 0;
        }

        .time-axis-block.active .time-axis-div {
            border: 3px solid #3399FF;
        }

        .time-axis-div .axis-name,
        .time-axis-div .axis-time {
            white-space: nowrap;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
        }

        .base-info {
            padding: 10px 0;
            margin-bottom: 10px;
            background-color: #fff;
            font-size: 15px;
        }

        .info .ibox-title,
        .info .ibox-content {
            background: none;
        }

        .info .ibox-title {
            min-height: 1em;
        }

        .info .ibox-title h3 {
            margin-bottom: 0;
        }

        .info .ibox-content {
            padding: 5px 15px;
        }

        #clinic {
            margin-bottom: 0;
        }
        .ui-th-column, .ui-jqgrid .ui-jqgrid-htable th.ui-th-column {
            padding: 8px;
        }
    </style>
</head>

<body>


<div class="ares-px-lg info">
    <div class="row">
        <h3>基本信息</h3>
    </div>

    <div class="row base-info">
        <span style="margin-left: 5%">患者编号：</span><span id="number">-</span>
        <span style="margin-left: 5%">姓名：</span><span id="name">-</span>
        <span style="margin-left: 5%">性别：</span><span id="sex">-</span>
        <span style="margin-left: 5%">年龄：</span><span id="age">-</span>
        <span style="margin-left: 5%">医保类别：</span><span id="insurance-type">-</span>
    </div>


    <div id="time-axis" class="time-axis"></div>

    <div class="row hide" id="out-record">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h3 class="inline-block">转诊记录</h3>

                <div id="transfer-out-btn" class="ibox-tools hide">
                    <a class="btn btn-xs btn-primary btn-w-80" href="#">新建</a>
                </div>
            </div>
            <div class="ibox-content">
                <table class="table table-bordered" id="transfer-out">
                    <thead>
                    <tr>
                        <th>序号</th>
                        <th>转入医院</th>
                        <th>接诊医生</th>
                        <th>转诊时间</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody id="transfer-out-tbody">

                    </tbody>
                </table>
            </div>
        </div>
    </div>

    <div class="row hide" id="in-record">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h3 class="inline-block">转诊记录</h3>

                <div id="transfer-in-btn" class="ibox-tools hide">
                    <a class="btn btn-xs btn-primary btn-w-80" href="#">新建</a>
                </div>
            </div>
            <div class="ibox-content">
                <table class="table table-bordered" id="transfer-in">
                    <thead>
                    <tr>
                        <th>序号</th>
                        <th>转出医院</th>
                        <th>转诊创建人</th>
                        <th>接诊时间</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody id="transfer-in-tbody">

                    </tbody>
                </table>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h3 class="inline-block">病历记录</h3>

                <div id="clinic-btn" class="ibox-tools hide">
                    <a class="btn btn-xs btn-primary btn-w-80" href="#" onclick="newClinic();">新建</a>
                </div>
            </div>
            <div class="ibox-content">
                <table class="table table-bordered hide" id="clinic">
                    <thead>
                    <tr>
                        <th>序号</th>
                        <th>文档名称</th>
                        <th>创建人</th>
                        <th>记录时间</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody id="clinic-tbody">

                    </tbody>
                </table>
                <div class="jqGrid_wrapper" style="text-align: center;">
                    <div id="clinic_norecords">没有查询记录！</div>
                </div>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h3 class="inline-block">康复处方</h3>

                <div id="prcp-btn" class="ibox-tools hide">
                    <a class="btn btn-xs btn-primary btn-w-80" onclick="newTrainingPrcp()">
                        新建</a>
                </div>
            </div>
            <div class="ibox-content">
                <div class="row" id="prcps_div">
                    <div class="col-lg-12">
                        <div class="jqGrid_wrapper" style="text-align: center">
                            <div class="hide" id="prcps_table">
                                <table id="prcps_table2"></table>
                            </div>
                            <div id="prcps_norecords">没有查询记录！</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h3 class="inline-block">康复训练方案</h3>

                <div id="training-plan-btn" class="ibox-tools hide">
                    <a class="btn btn-xs btn-primary btn-w-80" href="#" style="color: white">新建</a>
                </div>
            </div>
            <div class="ibox-content">
                <table class="table table-bordered hide" id="training-plan">
                    <thead>
                    <tr>
                        <th>序号</th>
                        <th>文档名称</th>
                        <th>创建人</th>
                        <th>记录时间</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody id="training-plan-tbody">
                    </tbody>
                </table>
                <div class="jqGrid_wrapper" style="text-align: center;">
                    <div id="training_plan_norecords">没有查询记录！</div>
                </div>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h3 class="inline-block">治疗记录</h3>

                <div id="record-btn" class="ibox-tools hide">
                    <a class="btn btn-xs btn-primary btn-w-80" href="#">新建</a>
                </div>
            </div>
            <div class="ibox-content">

                <table class="table table-bordered hide" id="treatment-record">
                    <thead>
                    <tr>
                        <th>序号</th>
                        <th>文档名称</th>
                        <th>创建人</th>
                        <th>记录时间</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody id="treatment-record-tbody">

                    </tbody>
                </table>
                <div class="jqGrid_wrapper" style="text-align: center;">
                    <div id="treatment_record_norecords">没有查询记录！</div>
                </div>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h3 class="inline-block">检查报告</h3>

                <div id="report-btn" class="ibox-tools hide">
                    <a class="btn btn-xs btn-primary btn-w-80" href="#" onclick="addReport()">上传</a>
                </div>
            </div>
            <div class="ibox-content">
                <table class="table table-bordered hide" id="report">
                    <thead>
                    <tr>
                        <th>序号</th>
                        <th>文档名称</th>
                        <th>创建人</th>
                        <th>记录时间</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody id="inspection_report">

                    </tbody>
                </table>
                <div class="jqGrid_wrapper" style="text-align: center;">
                    <div id="report_norecords">没有查询记录！</div>
                </div>
            </div>
        </div>
    </div>
</div>


<div id="time-axis-modal" class="time-axis-block hide">
    <div class="time-axis-icon">
        <i class="iconfont icon-concentric-circles"></i>
    </div>
    <div class="time-axis-div">
        <div class="axis-out">
            <!--     		<p class='text-center'><b>转出医院</b></p> -->
            <p class="axis-name"></p>
            <!--     		<p class='text-center'><b>转出时间</b></p> -->
            <p class="axis-time"></p>
        </div>
        <div style='height: 1em;'></div>
        <div class="axis-in">
            <!--     		<p class='text-center'><b>转入医院</b></p> -->
            <p class="axis-name"></p>
            <!--     		<p class='text-center'><b>转入时间</b></p> -->
            <p class="axis-time"></p>
        </div>
    </div>
</div>
<script src="../../plugins/jquery-3.2.1.min.js"></script>
<script src="../../legacy/plugins/jquery.cookie.js"></script>
<script src="../../legacy/plugins/jqGrid/i18n/grid.locale-en.js"></script>
<script src="../../legacy/plugins/jqGrid/jquery.jqGrid.min.js"></script>
<script src="../../legacy/plugins/jqpagination/jquery.jqpagination.min.js"></script>
<script src="../../legacy/plugins/toastr/toastr.min.js"></script>
<script src="../../legacy/plugins/iCheck/icheck.min.js"></script>
<script src="../../legacy/plugins/autosize.js"></script>
<script src="../../legacy/plugins/jquery.PrintArea.js"></script>
<script src="../../legacy/js/fast-recovery.js"></script>
<script src="../../legacy/js/reuse.js"></script>
<script type="text/javascript" src="../../plugins/layui/layui.js"></script>
<script type="text/javascript" src="../../aresExtends/config/layuiConfig.js"></script>
<script>
    var newClinic,newTrainingPrcp,addReport;
    layui.use(['utils', 'filters', 'greyServices', 'mandyServices','qs'], function (utils, filters, greyServices, mandyServices, qs) {
        var localHash = location.hash,
            queryStr = localHash.split('?')[1],
            routerParams = top.layui.routers.params,
            routerQuery = queryStr ? qs.parse(queryStr) : {};
        console.log(localHash, queryStr, routerParams, routerQuery)
        var number = $("#number");
        var namea = $("#name");
        var sex = $("#sex");
        var age = $("#age");
        var insuranceType = $("#insurance-type");

        //var id = $.getUrlParam("emr_id");
        var emrId = routerParams.emrId;
        var transferId = routerQuery.transferId;
        var outInType = routerQuery.type;//0：转出， 1：转入
        var id_card = routerQuery.idCard;
        var patientId = "";
        var hospitalId = null;
        var treatGroupName = null;


        showBtn();

        /* //转入
    if (transferId != null && outInType != null) {
        getReferral(transferId, outInType);
    }
    //转出，我的患者
    else {
        getReferralList(emrId);
    } */


        //getReferralList(id);
        loadTrainingPrcpList(emrId);
        loadTrainingPlanList();
        loadingTrainingRecordList();
        loadingClinicList();
        loadingReport();


        //jqGrid宽度自适应
        function pageInit() {
            $(".jqGrid_wrapper").bind('resize', function () {
                var width = $('.jqGrid_wrapper').width();
                $("#training_prcps_table2").setGridWidth(width);
                $("#evaluate_table2").setGridWidth(width);
            });
        }

        pageInit();

        //治疗组
        mandyServices.mandy_get_my_treat_group_syn().then(function (res) {
            treatGroupName = res.data.name;
        });

        //设置患者基本信息
        mandyServices.mandy_get_emr(emrId, transferId, id_card).then(function (res) {
            var data = res.data;
            patientId = data.patient.id;
            number.text(encryptNumber(data.number, 6, 7, "*******"));
            namea.text(getPrivatePatientName(data.patient.name));
            sex.text(filters.sexFormat(data.patient.sex));
            age.text(filters.ageFormat(data.patient.birthday));
            hospitalId = data.hospital.id;
            insuranceType.text(filters.insuranceTypeFormat(data.insurance_type));
        })

        function removeNotice(target) {
            $(target).parent().remove();
        }


        mandyServices.mandy_get_referral_history(emrId).then(function (res) {
            var data = res.data;
            console.log("+++++++++时间轴++++++++++")
            console.log(data)
            console.log("+++++++++时间轴++++++++++")
            $("#time-axis").empty();
            var lists = data.list;
            if (lists[0] == "null" || lists[0] == null || !lists) {
                var p = $("<p class='bg-info'><button type='button' class='close' onclick=removeNotice(this) aria-label='Close'><span aria-hidden='true'>&times;</span></button>没有相关的转诊信息</p>");
                p.css({"padding": "1em", "border-radius": "10px", "color": "red"});
                $("#time-axis").append(p);
                return;
            }
            var index = data.map.index;
            $.each(lists, function (idx, list) {
                var clone = $("#time-axis-modal").clone(true, true).removeAttr("id").removeClass("hide");
                var out_hospital_p = clone.find(".axis-out .axis-name"),
                    out_time_p = clone.find(".axis-out .axis-time"),
                    in_hospital_p = clone.find(".axis-in .axis-name"),
                    in_time_p = clone.find(".axis-in .axis-time");
                var in_time = new Date(list.in_time).format("YYYY-MM-DD"),
                    out_time = new Date(list.out_time).format("YYYY-MM-DD");

                if (list.out_hospital && list.out_hospital != 'null') {
                    out_hospital_p.text('转出医院 : ' + list.out_hospital).attr("title", list.out_hospital);
                    if (list.out_time && list.out_time != 'null') {
                        out_time_p.text('转出时间 : ' + out_time).attr('title', out_time);
                    }
                }

                if (list.in_hospital && list.in_hospital != 'null') {
                    in_hospital_p.text('转入医院 : ' + list.in_hospital).attr("title", list.in_hospital);
                    if (list.in_time && list.in_time != 'null') {
                        in_time_p.text('转入时间 : ' + in_time).attr('title', in_time);
                    }
                }

                $("#time-axis").append(clone);
                //转诊的时间轴高亮显示改为上一家转诊医院，即倒数第二个，倒数第一个为当前医院
                //$("#time-axis .time-axis-block:first").addClass("active");

                if (idx == lists.length - 1) {
                    clone.addClass("active");
                }

            })
        })

        function getReferral(transferId, outInType) {
            mandyServices.mandy_get_referral_emr(transferId, outInType).then(function (res) {
                var data = res.data;
                if (0 == outInType) {
                    var tb = $("#transfer-out-tbody");
                    var tr = $("<tr>");
                    var tdId = $("<td>");
                    var tdInhospital = $("<td>");
                    var tdReciveDoctor = $("<td>");
                    var tdOutTime = $("<td>");
                    var tdOption = $("<td>");

                    tdId.text("1");
                    if (data.in_hospital != null) {
                        tdInhospital.text(data.in_hospital.name);
                    }
                    if (data.receive_medical != null) {
                        tdReciveDoctor.text(data.receive_medical.name);
                    }
                    var outTime = new Date(data.out_time).format("YYYY-MM-DD hh:mm");
                    tdOutTime.html(outTime.split(" ")[0] + "&nbsp;&nbsp;&nbsp;&nbsp;" + outTime.split(" ")[1]);
                    tdOption.text("查看");
                    tr.append(tdId, tdInhospital, tdReciveDoctor, tdOutTime, tdOption);
                    tb.append(tr);

                    //$("#out-record").removeClass("hide");
                }
                else if (1 == outInType) {
                    var tb = $("#transfer-in-tbody");
                    var tr = $("<tr>");
                    var tdId = $("<td>");
                    var tdOuthospital = $("<td>");
                    var tdSendDoctor = $("<td>");
                    var tdInTime = $("<td>");
                    var tdOption = $("<td>");

                    tdId.text("1");
                    if (data.out_hospital != null) {
                        tdOuthospital.text(data.out_hospital.name);
                    }
                    if (data.send_medical != null) {
                        tdSendDoctor.text(data.send_medical.name);
                    }
                    var inTime = new Date(data.in_time).format("YYYY-MM-DD hh:mm");
                    tdInTime.html(inTime.split(" ")[0] + "&nbsp;&nbsp;&nbsp;&nbsp;" + inTime.split(" ")[1]);
                    tdOption.text("查看");
                    tr.append(tdId, tdOuthospital, tdSendDoctor, tdInTime, tdOption);
                    tb.append(tr);

                    //$("#in-record").removeClass("hide");
                }

            });
        }

        function getReferralList(emrId) {
            mandyServices.mandy_get_referral_emr_list(emrId).then(function (res) {
                var data = res.data;
                var tb = $("#transfer-in-tbody");
                tb.empty();
                $.each(data.list, function (idx, val) {
                    var tr = $("<tr>");

                    var tdId = $("<td>");
                    var tdOuthospital = $("<td>");
                    var tdSendDoctor = $("<td>");
                    var tdInTime = $("<td>");
                    var tdOption = $("<td>");

                    tdId.text(idx + 1);
                    if (val.out_hospital != null) {
                        tdOuthospital.text(val.out_hospital.name);
                    }
                    if (val.send_medical != null) {
                        tdSendDoctor.text(val.send_medical.name);
                    }
                    tdInTime.text(new Date(val.in_time).format("YYYY-MM-DD hh:mm"));
                    var lookA = $("<a style='text-decoration:underline;color:#6d9dcd' href='#/emr/info/"+val.out_emr.id+"?type=1&transferId="+val.id+"'>查看</a>");
//                tdOption.text("查看");
                    tdOption.append(lookA);
                    tr.append(tdId, tdOuthospital, tdSendDoctor, tdInTime, tdOption);
                    tb.append(tr);

                    //$("#in-record").removeClass("hide");
                });
            });
        }

        function showBtn() {
            var job = getCookie("job");
            console.log("hospitalId======", hospitalId);
            if (job == "doctor" && hospitalId == getCookie("hospital")) {
                $("#clinic-btn").removeClass("hide");
                $("#report-btn").removeClass("hide");
                $("#prcp-btn").removeClass("hide");
            } else if (job == "therapist" && hospitalId == getCookie("hospital")) {
                mandyServices.mandy_get_newest_prcp_item(emrId).then(function (res) {
                    var data = res.data;
                    console.log("newest", data);
//                $("#training-plan-btn a").attr("href","javascript:newTrainingPlan("+JSON.stringify(data)+");");
                    $("#training-plan-btn a").bind("click", data, newTrainingPlan);
                    $("#training-plan-btn").removeClass("hide");
                }, function (data) {
                    $("#training-plan-btn a").attr("disabled", "true");
                    $("#training-plan-btn a").removeClass("btn-primary");
                    $("#training-plan-btn a").addClass("btn-default");
                    $("#training-plan-btn").removeClass("hide");
                });
            }
        }

        newClinic = function () {
            var query = {
                readonly: false
            }
            utils.pushTopRoute('/emr/clinicDetail/' + routerParams.emrId, query);
        }
        newTrainingPrcp = function () {
            utils.pushTopRoute('/training/create/' + routerParams.emrId);
        }

        function loadTrainingPrcpList(emrId) {

            console.log("loadItems>>EMRID:" + emrId);

            greyServices.grey_get_prescription_by_emr_id(emrId, null, "emr_history").then(function (res) {
                var data = res.data,
                    list = data.prescription_list == null ? [] : data.prescription_list;

                if (list.length == 0) {
                    $("#prcps_norecords").show();
                } else {
                    $("#prcps_table").removeClass("hide");
                    $("#prcps_norecords").hide();
                }


                $("#prcps_table").empty();
                $("#prcps_table").append("<table id='training_prcps_table2' style='text-align: center;'></table>");

                var index = 1;
                $("#training_prcps_table2").jqGrid({
                    data: list,
                    datatype: "local",
                    height: "auto",
                    autowidth: true,
                    shrinkToFit: true,
                    rowNum: 10000,
//                rownumbers:true,
                    colNames: ['ID', '序号', '文档名称', '创建人', '记录时间', '操作'],
                    colModel: [
                        {name: 'id', index: 'id', width: 0, hidden: true},
                        {
                            name: 'index',
                            index: 'index',
                            width: 40,
                            align: 'center',
                            formatter: function (cellvalue, options, rowObject) {
                                return index++;
                            }
                        },

                        {
                            name: 'type',
                            index: 'type',
                            width: 60,
                            align: "center",
                            formatter: function (cellvalue, options, rowObject) {
                                if (cellvalue == "1") {
                                    return "评估处方";
                                } else if (cellvalue == "2") {
                                    return "训练处方";
                                }
                            }
                        },
                        {name: 'creator.name', index: 'creator.name', width: 60, align: "center"},
                        {
                            name: 'create_time',
                            index: 'create_time',
                            width: 120,
                            align: "center",
                            formatter: function (cellvalue, options, rowObject) {
                                var recordTime = new Date(cellvalue).format("YYYY-MM-DD hh:mm");
                                return "<span>" + recordTime.split(" ")[0] + "&nbsp;&nbsp;&nbsp;&nbsp;" + recordTime.split(" ")[1] + "</span>";
//                        return new Date(cellvalue).format("YYYY-MM-DD hh:mm");
                            }
                        },
                        {
                            name: 'option',
                            index: 'option',
                            width: 50,
                            align: "center",
                            formatter: function (cellvalue, options, rowObject) {
                                return "<a href='#' style='text-decoration:underline;color:#6d9dcd' onclick='openPrcpDetail(" + rowObject.id + "," + rowObject.type + ")'>查看</a>";

//                        var a= $("<a href='#' style='text-decoration:underline;color:#6d9dcd' >");
//                        a.text("查看");
//                        a.attr("onclick", "openPrcpDetail("+rowObject.id+ "," + rowObject.type + ")");
//                       return a.prop("outerHTML");
                            }
                        }
                    ],
                    viewrecords: true,
                    hidegrid: false,
                    onSortCol: function (idx, iCol, sortorder) {
                        index = index - list.length;
                    }
                });
            });
        }

        function openPrcpDetail(prcpId, prcpType) {
            selectPrcpId = prcpId;
            if (prcpType == 1) {
                utils.pushTopRoute('/evaluation/detail/' + routerParams.emrId + '/' + prcpId, {isReferralHistory: 'emr_history'});
            } else if (prcpType == 2) {
                utils.pushTopRoute('/training/detail/' + routerParams.emrId, {selectPrcpId: prcpId, isReferralHistory: 'emr_history'});
            }

        }

        function newTrainingPlan(event) {
            var data = event.data;
            console.log("data", data);
            var query = {
                myParam1: 'old',
                myParam2: 'add',
                myParam3: 'type',
                isReferralHistory: 'emr_history',
                item_id: data.list[0].id,
                itemType: data.list[0].prcp_item_type.name,
                isGeneral: treatGroupName == '全科治疗组' ? 1 : 0
            };
            utils.pushTopRoute('/training/plan/' + routerParams.emrId, query);
        }

        function lookTrainingPlan(data) {
            var query = {
                myParam1: 'old',
                myParam2: 'view',
                myParam3: 'group',
                isReferralHistory: 'emr_history',
                itemType: data.prescription_item.prcp_item_type.name,
                transferId: routerQuery.transferId
            };
            utils.pushTopRoute('/training/plan/' + routerParams.emrId, query);
        }

        function loadTrainingPlanList() {
            mandyServices.mandy_get_newest_training_plan(emrId, "emr_history").then(function (res) {
                var data = res.data;
                if (data.list != null && data.list.length > 0) {
                    $("#training-plan").removeClass("hide");
                    $("#training_plan_norecords").addClass("hide");
                    var tb = $("#training-plan-tbody");
                    tb.empty();
                    $.each(data.list, function (idx, val) {
                        var tr = $("<tr>");

                        var tdId = $("<td>");
                        var tdTextName = $("<td>");
                        var tdCreator = $("<td>");
                        var tdCreateTime = $("<td>");
                        var tdOption = $("<td>");
                        var lookA = $("<a style='text-decoration:underline;color:#6d9dcd' href='javascript:lookTrainingPlan(" + JSON.stringify(val) + ")'>查看</a>")

                        tdId.text(idx + 1);
                        tdTextName.text("康复训练方案（" + val.prescription_item.prcp_item_type.name + "）");
                        tdCreator.text(val.creator.name);
                        var recordTime = new Date(val.createTime).format("YYYY-MM-DD hh:mm");
                        tdCreateTime.html(recordTime.split(" ")[0] + "&nbsp;&nbsp;&nbsp;&nbsp;" + recordTime.split(" ")[1]);
                        tdOption.append(lookA);
                        tr.append(tdId, tdTextName, tdCreator, tdCreateTime, tdOption);
                        tb.append(tr);
                    })
                }
                console.log("newest training plan", data);
            })
        }

        function lookTreatmentRecord(data) {
            var query = {
                isReferralHistory: 'emr_history',
                itemType: data.prescription_item.prcp_item_type.name,
                transferId: routerQuery.transferId
            };
            utils.pushTopRoute('/training/record/' + routerParams.emrId, query);
        }

        function loadingTrainingRecordList() {
            mandyServices.mandy_get_newest_treatment_records(emrId, "emr_history").then(function (res) {
                var data = res.data;
                if (data.list != null && data.list.length > 0) {
                    $("#treatment-record").removeClass("hide");
                    $("#treatment_record_norecords").addClass("hide");
                    var tb = $("#treatment-record-tbody");
                    tb.empty();
                    $.each(data.list, function (idx, val) {
                        var tr = $("<tr>");

                        var tdId = $("<td>");
                        var tdTextName = $("<td>");
                        var tdCreator = $("<td>");
                        var tdCreateTime = $("<td>");
                        var tdOption = $("<td>");
                        var lookA = $("<a style='text-decoration:underline;color:#6d9dcd' href='javascript:lookTreatmentRecord(" + JSON.stringify(val) + ")'>查看</a>")

                        tdId.text(idx + 1);
                        tdTextName.text("治疗记录（" + val.prescription_item.prcp_item_type.name + "）");
                        tdCreator.text(val.therapist.name);
                        var recordTime = new Date(val.finish_time).format("YYYY-MM-DD hh:mm");
                        tdCreateTime.html(recordTime.split(" ")[0] + "&nbsp;&nbsp;&nbsp;&nbsp;" + recordTime.split(" ")[1]);
                        tdOption.append(lookA);
                        tr.append(tdId, tdTextName, tdCreator, tdCreateTime, tdOption);
                        tb.append(tr);
                    })
                }
                console.log(data);
            });
        }

        addReport = function() {
            var query = {
                isReferralHistory: 'emr_history',
            };
            utils.pushTopRoute('/report/create/' + routerParams.emrId, query);
        }

        function loadingClinicList() {
            mandyServices.mandy_get_clinic_list(emrId, "emr_history", 1, 10000).then(function (res) {
                var data = res.data;
                if (data.list != null && data.list.length > 0) {
                    $("#clinic").removeClass("hide");
                    $("#clinic_norecords").addClass("hide");
                    var tb = $("#clinic-tbody");
                    tb.empty();
                    $.each(data.list, function (idx, val) {
                        var tr = $("<tr>");
                        var tdId = $("<td>");
                        var tdTextName = $("<td>");
                        var tdCreator = $("<td>");
                        var tdCreateTime = $("<td>");
                        var tdOption = $("<td>");
                        var lookA = $("<a style='text-decoration:underline;color:#6d9dcd' href='javascript:lookClinic(" + JSON.stringify(val) + ")'>查看</a>")
//
                        tdId.text(idx + 1);
                        tdTextName.text("病历记录");
                        tdCreator.text(val.creator.name);
                        var recordTime = new Date(val.create_time).format("YYYY-MM-DD hh:mm");
                        tdCreateTime.html(recordTime.split(" ")[0] + "&nbsp;&nbsp;&nbsp;&nbsp;" + recordTime.split(" ")[1]);
                        tdOption.append(lookA);
                        tr.append(tdId, tdTextName, tdCreator, tdCreateTime, tdOption);
                        tb.append(tr);
                    });
                }
                console.log(data);
            });
        }

        function lookClinic(data) {
            var query = {
                isReferralHistory: 'emr_history',
                transferId: routerQuery.transferId,
                clinicId: data.id
            };
            utils.pushTopRoute('/emr/clinicDetail/' + routerParams.emrId, query);
        }

        function loadingReport() {
            mandyServices.mandy_get_inspection_report_list(patientId, emrId, "emr_history").then(function (res) {
                var data = res.data;
                if (data.inspection_report_list != null && data.inspection_report_list.length > 0) {
                    $("#report").removeClass("hide");
                    $("#report_norecords").addClass("hide");
                    var tb = $("#inspection_report");
                    tb.empty();
                    $.each(data.inspection_report_list, function (idx, val) {
                        var tr = $("<tr>");
                        var tdId = $("<td>");
                        var tdTextName = $("<td>");
                        var tdCreator = $("<td align='center'>");
                        var tdCreateTime = $("<td>");
                        var tdOption = $("<td>");
                        var lookA = $("<a style='text-decoration:underline;color:#6d9dcd' href='javascript:lookReport(" + emrId + "," + val.id + ")'>查看</a>")
//
                        tdId.text(idx + 1);
                        tdTextName.text("检查报告");
                        if (val.creator != null) {
                            tdCreator.text(val.creator.name);
                        }
                        var recordTime = new Date(val.check_time).format("YYYY-MM-DD");
//                    tdCreateTime.html(recordTime.split(" ")[0] + "&nbsp;&nbsp;&nbsp;&nbsp;" + recordTime.split(" ")[1]);
                        tdCreateTime.html(recordTime);
                        tdOption.append(lookA);
                        tr.append(tdId, tdTextName, tdCreator, tdCreateTime, tdOption);
                        tb.append(tr);
                    });
                }
                console.log(data);
            });
        }

        function lookReport(emrId, reportId) {
            var query = {
                isReferralHistory: 'emr_history',
                transferId: routerQuery.transferId,
            };
            utils.pushTopRoute('/report/detail/' + routerParams.emrId + '/' + reportId, query);
        }

        function lookEmr(data) {
            var query = {
                isReferralHistory: 'emr_history',
                transferId: data.id,
                type: 1
            };
            utils.pushTopRoute('/emr/info/' + data.out_emr.id, query);
        }
    })
</script>

</body>
</html>



